﻿#region 程序集引用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Configuration;
#endregion


namespace Zhang
{
    namespace AdminPage
    {
        /// <summary>
        /// 平台后台基类 Controller
        /// </summary>
        public partial class BaseController : System.Web.Mvc.Controller
        {
            /// <summary>
            /// 操作名称
            /// </summary>
            public string OpName { get; set; }

            /// <summary>
            /// 编辑 : True
            /// 添加　：false
            /// </summary>
            public bool IsEdit { get; set; }

            protected override IAsyncResult BeginExecute(RequestContext requestContext, AsyncCallback callback, object state)
            {
                if (!string.IsNullOrEmpty(requestContext.HttpContext.Request.QueryString["act"]) && requestContext.HttpContext.Request.QueryString["act"].ToLower() == "edit")
                {
                    OpName = "编辑";
                    ViewBag.OpName = "编辑";
                    IsEdit = true;
                    ViewBag.IsEdit = 1;
                }
                else
                {
                    OpName = "添加";
                    ViewBag.OpName = "添加";
                    IsEdit = false;
                    ViewBag.IsEdit = 0;
                }

                // 设置分页大小
                if (!string.IsNullOrEmpty(requestContext.HttpContext.Request.QueryString["pgSize"]) && Zhang.Utils.OpString.IsNumber(requestContext.HttpContext.Request.QueryString["pgSize"]))
                {
                    _pageSize = int.Parse(requestContext.HttpContext.Request.QueryString["pgSize"]);
                    requestContext.HttpContext.Response.Cookies.Add(new System.Web.HttpCookie("ABSHOPPAGESIZE", _pageSize.ToString()));
                }
                else
                {
                    if (requestContext.HttpContext.Request.Cookies["ABSHOPPAGESIZE"] != null && true == Utils.OpString.IsNumber(requestContext.HttpContext.Request.Cookies["ABSHOPPAGESIZE"].Value))
                    {
                        _pageSize = int.Parse(requestContext.HttpContext.Request.Cookies["ABSHOPPAGESIZE"].Value);
                    }
                    else
                    {
                        _pageSize = int.Parse(ConfigurationManager.AppSettings["ListPageSize"]);
                    }
                }

                // 页码设置
                if (Utils.OpString.IsNumber(requestContext.HttpContext.Request.QueryString["rsCount"]) == false)
                {
                    TotalRecord = 0;
                }
                else
                {
                    TotalRecord = int.Parse(requestContext.HttpContext.Request.QueryString["rsCount"]);
                }

                if (Utils.OpString.IsNumber(requestContext.HttpContext.Request.QueryString["pg"]) == true)
                {
                    _pageIndex = int.Parse(requestContext.HttpContext.Request.QueryString["pg"]);
                }
                else
                {
                    _pageIndex = 1;
                }

                return base.BeginExecute(requestContext, callback, state);
            }
        }
    }
}
